public class Test {

        public int totalFruit(int[] fruits) {
            int[] hash = new int[fruits.length];
            int len =0 ;
            for(int left =0 ,right = 0, count =0; right < fruits.length ; right ++){
                int in = fruits[right];
                if(hash[in] == 0){
                    count ++;
                }
                hash[in]++;
                while(count > 2){
                    int out = fruits[left];
                    hash[out] --;
                    if(hash[out] == 0){
                        count --;
                    }
                    left++;

                }
                len = Math.max(len ,right- left +1);
            }
            return len;


        }


}
